package com.leetcode.LC;

public class LC922 {
    public int[] sortArrayByParityII(int[] A) {

        int i = 0, j = 1;
        while (i < A.length && j < A.length) {
            if (A[i] % 2 == 0 && A[j] % 2 == 1) {
                i += 2;
                j += 2;
            } else if (A[i] % 2 == 1 && A[j] % 2 == 0) {
                int tmp;
                tmp = A[i];
                A[i] = A[j];
                A[j] = tmp;
            } else if (A[i] % 2 == 0 && A[j] % 2 == 0) {
                i += 2;
            } else if (A[i] % 2 == 1 && A[j] % 2 == 1) {
                j += 2;
            }
        }

        return A;
    }

    public static void main(String[] args) {
        for (int i : new LC922().sortArrayByParityII(new int[]{3, 2})) {
            System.out.print(i + ",");
        }
    }
}
